class SubmittersController < ApplicationController
  before_filter :authorize, :except => :login
  before_filter :setup
  before_filter :verify       ##rk: applies to edit, create...

  # GET /submitters
  # GET /submitters.xml
  def index
    @submitters = Submitter.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @submitters }
    end
  end

  # GET /submitters/1
  # GET /submitters/1.xml
  def show
    @submitter = Submitter.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @submitter }
    end
  end

  # GET /submitters/new
  # GET /submitters/new.xml
  def new
    @submitter = Submitter.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @submitter }
    end
  end

  # GET /submitters/1/edit
  def edit
    @submitter = Submitter.find(params[:id])
  end

  # POST /submitters
  # POST /submitters.xml
  def create
    @submitter = Submitter.new(params[:submitter])

    respond_to do |format|
      if @submitter.save
        flash[:notice] = 'Submitter was successfully created.'
        format.html { redirect_to(@submitter) }
        format.xml  { render :xml => @submitter, :status => :created, :location => @submitter }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @submitter.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /submitters/1
  # PUT /submitters/1.xml
  def update
    @submitter = Submitter.find(params[:id])

    respond_to do |format|
      if @submitter.update_attributes(params[:submitter])
        flash[:notice] = 'Submitter was successfully updated.'
        format.html { redirect_to(@submitter) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @submitter.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /submitters/1
  # DELETE /submitters/1.xml
  def destroy
    @submitter = Submitter.find(params[:id])
    @submitter.destroy

    respond_to do |format|
      format.html { redirect_to(submitters_url) }
      format.xml  { head :ok }
    end
  end

private
  def verify
    ##rk: need this to be an actual page & have a logout button.
    render :text => "You need to be an administrator to access this page", :status => 403 unless @user && @user.is_admin?
  end

end

# vim:ts=2:et:sw=2
